source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
"-------------------------------

"--------------------
" map leader key -> , G.song
"--------------------
"let g:mapleader = ','
let g:mapleader = ","
"--------------------

"=========settings========

set nocompatible
if has("autocmd")
  filetype plugin indent on
endif
"--------------------
" 设置主题
"--------------------
colorscheme monokai
set t_Co=256
"--------------------

"--------------------
" 设置字体
"--------------------
" set gfn=Monaco:h14
" set gfn=Monaco:h14
" 测试中文 站
" set gfn=Monaco:h14
" set gfn=YaHeiMonoGS:h14
set gfn=GSMonacoMono:h14
"set gfn=FiraCodeGS:h14
set ambiwidth=double
"--------------------

"--------------------
" 编码设置
"--------------------
set encoding=utf-8
set langmenu=zh_CN.UTF-8
set makeencoding=char
set fileencodings=utf-8,gbk,gb2312,ucs-bom,cp936,big5,gb18030,shift-jis,latin1
source $VIMRUNTIME/delmenu.vim
language messages zh_CN.utf-8
set helplang=cn
"-----------------------

"-----------------------
"状态栏工具栏代码预览窗口
"-----------------------
"au GUIEnter * simalt ~x " 窗口启动时自动最大化
set go-=m " 隐藏菜单栏
set go-=T " 隐藏工具栏
set go-=L " 隐藏左侧滚动条
"set go-=r " 隐藏右侧滚动条
"set go-=b " 隐藏底部滚动条
set stal=0 " 隐藏Tab栏
set cot-=preview " 隐藏代码预览窗口
"----------------------

"----------------------
" 设置缩进,行号和波浪线
"----------------------
set nu rnu sw=4 ts=4 sts=4 et tw=78 shiftwidth=4 tabstop=4 softtabstop=4 smarttab autoindent
hi NonText guifg=bg
"----------------------

"----------------------
" 设置光标当前行高亮
"----------------------
set cursorline
"----------------------

"----------------------
" 取消自动备份及产生swp文件
"----------------------
set noundofile
set nobackup
set noswapfile
"---------------------

"----------------------
"显示所有conceal
"----------------------
set conceallevel=0

"----------------------
"禁止使用箭头键。
"----------------------
nnoremap <Left> :echoe "Use h"<CR>
nnoremap <Right> :echoe "Use l"<CR>
nnoremap <Up> :echoe "Use k"<CR>
nnoremap <Down> :echoe "Use j"<CR>

"----------------------
"在窗口间移动。
"----------------------
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l

"==============Plugins==============

"--------------------
"  vim-plug
" 设置插件安装  https://github.com/junegunn/vim-plug
"  recommend plugin list website:  https://vimawesome.com/
"--------------------
" Specify a directory for plugins
" - For Neovim: stdpath('data') . '/plugged'
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('D:/programs/vim/vimfiles/plugins')
" Make sure you use single quotes

Plug 'mhinz/vim-startify'
Plug 'ryanoasis/vim-devicons'
Plug 'scrooloose/nerdtree'
Plug 'majutsushi/tagbar'
Plug 'junegunn/fzf.vim'
Plug 'junegunn/vim-easy-align'
Plug 'tpope/vim-fugitive'
Plug 'jiangmiao/auto-pairs'
Plug 'mattn/emmet-vim'
Plug 'scrooloose/nerdcommenter'
Plug 'terryma/vim-multiple-cursors'
Plug 'Shougo/neocomplete.vim'
Plug 'Shougo/neosnippet.vim'
Plug 'thinca/vim-quickrun'
" fetches https://github.com/ncm2/ncm2
Plug 'ncm2/ncm2'
Plug 'roxma/nvim-yarp'
Plug 'dhruvasagar/vim-table-mode'
Plug 'easymotion/vim-easymotion'

" Markdown {{{
Plug 'godlygeek/tabular'
Plug 'mzlogin/vim-markdown-toc'
Plug 'plasticboy/vim-markdown'
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() } }
Plug 'masukomi/vim-markdown-folding'
" }}}
" enable ncm2 for all buffers
" autocmd BufEnter * call ncm2#enable_for_buffer()

" IMPORTANT: :help Ncm2PopupOpen for more information
"set completeopt=noinsert,menuone,noselect

"测试中文字体

" NOTE: you need to install completion sources to get completions. Check
" our wiki page for a list of sources: https://github.com/ncm2/ncm2/wiki
"Plug 'ncm2/ncm2-bufword'
"Plug 'ncm2/ncm2-path'
" Initialize plugin system
call plug#end()

"--------------------

"--------------------
" nerdtree
" F2
"--------------------
nnoremap <silent> <F2> :NERDTreeToggle<CR>
let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'
let NERDTreeWinSize=20
"--------------------


"--------------------
" vim-easymotion, G.song
"--------------------
let g:EasyMotion_smartcase = 1
"let g:EasyMotion_startofline = 0 " keep cursor colum when JK motion
map <Leader><leader>h <Plug>(easymotion-linebackward)
map <Leader><Leader>j <Plug>(easymotion-j)
map <Leader><Leader>k <Plug>(easymotion-k)
map <Leader><leader>l <Plug>(easymotion-lineforward)
" 重复上一次操作, 类似repeat插件, 很强大
map <Leader><leader>. <Plug>(easymotion-repeat)
"--------------------

"------------------
" vim-airline
"------------------
"设置切换Buffer快捷键
nnoremap <C-tab> :bn<CR>
nnoremap <C-s-tab> :bp<CR>
let g:airline#extensions#whitespace#enabled = 0
let g:airline#extensions#tabline#enabled = 1
"设置powerline字体
let g:airline_powerline_fonts = 1
let g:airline_right_sep = '⮂'
let g:airline_left_sep = '⮀'
"-----------------------


"--------------------
" startify
" :SSave 保存当前项目
" :SLoad 加载指定项目
" :SDelete 删除指定项目
" :SClose 关闭当前文件
"--------------------
let g:startify_session_dir = $VIM.'/vimfiles/session'
let g:startify_files_number = 5
let g:startify_session_number = 5
"let g:startify_bookmarks = [{'快捷键' : '路径'}]
let g:startify_list_order = [
\ ['   最近项目:'],
\ 'sessions',
\ ['   最近文件:'],
\ 'files',
\ ['   快捷命令:'],
\ 'commands',
\ ['   常用书签:'],
\ 'bookmarks',
\ ]
let g:startify_commands = [
\ {'c': ['配置', 'vi $VIM/_vimrc']},
\ {'h': ['帮助', 'help howto']},
\ {'v': ['版本', 'version']}
\ ]
"-------------------

"--------------------
" devicons
"--------------------
let g:WebDevIconsUnicodeDecorateFolderNodes = 1
let g:DevIconsEnableFoldersOpenClose = 1
"--------------------

"-----------------
" Tagbar
" F3
"-----------------
nnoremap <silent> <F3> :TagbarToggle<CR>
let g:tagbar_iconchars = ['▸', '▾']
let g:tagbar_width = 25
let g:tagbar_sort = 0
"-----------------

"-----------------
" fzf.vim
"-----------------
" Mapping selecting mappings
nmap <c-p> :Files<CR>
nmap <leader><tab> <plug>(fzf-maps-n)
xmap <leader><tab> <plug>(fzf-maps-x)
omap <leader><tab> <plug>(fzf-maps-o)

" Insert mode completion
imap <c-x><c-f> <plug>(fzf-complete-path)
imap <c-x><c-j> <plug>(fzf-complete-file-ag)
imap <c-x><c-l> <plug>(fzf-complete-line)
"-----------------

"-----------------
" vim-emmet
"-----------------
let g:user_emmet_expandabbr_key = '<C-l>'
"-----------------

"-----------------
" nerdcommenter
"-----------------
let g:NERDSpaceDelims = 1
"-----------------

"-----------------
" vim-markdown
"-----------------
let g:vim_markdown_folding_disabled = 1
let g:vim_markdown_toc_autofit = 1
"-----------------

"-----------------
" neocomplete.vim
"-----------------
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
let g:neocomplete#enable_at_startup = 1
let g:neocomplete#enable_smart_case = 1
let g:neocomplete#max_list=20
"-----------------

"-----------------
"neosnippet.vim
"-----------------
" 设置代码片段按键为ctrl+k(注意自动补全关键词为tab或ctrl+N)
imap <C-k> <Plug>(neosnippet_expand_or_jump)
smap <C-k> <Plug>(neosnippet_expand_or_jump)
xmap <C-k> <Plug>(neosnippet_expand_target))
" tab(ctrl+k)自动跳转下一个输入点
smap <expr><TAB> neosnippet#expandable_or_jumpable() ? "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
let g:neosnippet#snippets_directory=$VIM.'/vimfiles/snippets'
let g:neosnippet#disable_runtime_snippets = {'_' : 1}
let g:neosnippet#enable_snipmate_compatibility = 1
" 不显示输入标记
"if has('conceal')
"  set conceallevel=2 concealcursor=niv
"endif
"-----------------

"-----------------
" ale
"-----------------
let g:ale_sign_error = '✗'
let g:ale_sign_warning = '!'
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_insert_leave = 1
let g:ale_set_quickfix = 1
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
"-----------------

"-----------------
" vim-quickrun
" default keymap: <leader>r (\+r)
" input text: press :QuickRun < '1.txt' or :QuickRun <= 1(your input words)
"-----------------
let g:quickrun_config={"_":{"outputter":"message"}}
"let g:quickrun_config={'*':{'outputter/buffer/split':'25vsplit'}}
"-----------------

"-----------------
" vim-easy-align
"-----------------
vmap <Leader>a <Plug>(EasyAlign)
nmap <Leader>a <Plug>(EasyAlign)
if !exists('g:easy_align_delimiters')
  let g:easy_align_delimiters = {}
endif
let g:easy_align_delimiters['#'] = { 'pattern': '#', 'ignore_groups': ['String'] }
"-----------------
 
"-----------------
" vim-MarkdownPreview.nvim
"-----------------
" nnoremap <Leader> ch :update<Bar>silent ! start %:p<CR>
nmap <C-s> <Plug>MarkdownPreview
nmap <M-s> <Plug>MarkdownPreviewStop
nmap <C-p> <Plug>MarkdownPreviewToggle

"-----------------
" tab键跳出括号，兼容neocomplete By G.song
" ----------------
" 定义跳出括号函数，用于跳出括号
func! SkipPair()
    if getline('.')[col('.') - 1] == ')' || getline('.')[col('.') - 1] == ']' || getline('.')[col('.') - 1] == '"' || getline('.')[col('.') - 1] == "'" || getline('.')[col('.') - 1] == '}' || getline('.')[col('.') - 1] == '`' || getline('.')[col('.') - 1] == '>'
        return "\<ESC>la"
    else
        return "\t"
    endif
endfunc
" 将tab键绑定为跳出括号与neocomplete的taby设置冲突，所以绑定在neocomplete的下面。G.song 20181021
"inoremap <tab> <c-r>=SkipPair()<CR>
"-----------------
" neocomplete.vim
"-----------------
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : SkipPair()
inoremap jj <ESC>

"hi htmlh2 guifg=pink
"hi htmlh3 guifg=green
highlight mkdKeycode guifg=#ef5b9c
match mkdKeycode /\(`\)\@<!`[^`].\{-}``\@!/

map <F9> :call CompileRunGcc()<CR>
func! CompileRunGcc()
	exec "w"
	if &filetype == 'c'
		exec "!gcc % -o %<"
		exec "!time ./%<"
	elseif &filetype == 'cpp'
		exec "!g++ % -o %<"
		exec "!time ./%<"
	elseif &filetype == 'java' 
		exec "!javac %" 
		exec "!time java %<"
    elseif &filetype == 'html'
        exec "!firefox % &"
        exec "!time go run %"
"    elseif &filetype == 'mkd'
"        exec "!~/.vim/markdown.pl % > %.html &"
"        exec "!firefox %.html &"
	endif
endfunc
